﻿using System;
using System.Collections.Generic;

namespace Microsoft.Xna.Framework
{
    /// <summary>
    /// A collection of game services.
    /// </summary>
    public class GameServiceContainer : IServiceProvider
    {
        Dictionary<Type, object> services;

        #region Constructor
        /// <summary>
        /// Initializes a new instance of this class, which represents a collection of game services.
        /// </summary>
        public GameServiceContainer()
        {
            services = new Dictionary<Type, object>();
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Adds a service to the GameServiceContainer.
        /// </summary>
        /// <param name="type">The type of service to add.</param>
        /// <param name="provider">The service provider to add.</param>
        public void AddService(Type type, object provider)
        {
            services.Add(type, provider);
        }
        /// <summary>
        /// Gets the object providing a specified service.
        /// </summary>
        /// <param name="type">The type of service.</param>
        public object GetService(Type type)
        {
            object service;
            if (services.TryGetValue(type, out service))
                return service;

            return null;
        }
        /// <summary>
        /// Removes the object providing a specified service.
        /// </summary>
        /// <param name="type">The type of service.</param>
        public void RemoveService(Type type)
        {
            services.Remove(type);
        }
        #endregion
    }
}